<html>
	<head>
     <title>登录</title>	
    </head>	
		<body>
			<form method="post">
			<p>
				用户名：
				<input type="text" name="name" id="" value="" />
			</p>
            <p>
				密码：
				<input type="password" name="pasword" id="" value="" />
			</p>
			<p>
				验证码：
				<input type="text" maxlength="4" name="imageCode" id="" />
				<img src="yanzhangma.php" onclick="this.src='yanzhangma.php?t='+new Date().getTime()"/>
		    </p>
			<input type="submit" value="登录"/>
			</form>
		</body>
</html>
<?php
session_start();
$name=$_POST["name"];
$pasword=$_POST["pasword"];
$imageCode=$_POST["imageCode"];
$imageNum=$_SESSION["imageNum"];
if($name && $pasword){
	if($imageNum==$imageCode){
		//通过PDO连接MYSQL
     $db = new PDO("mysql:host=127.0.0.1;dbname=scholl;charset=utf8","root","123456");
	 $sql="select count(*) from stu where name=:name and pasword=:pasword";
	 $sth=$db->prepare($sql);
	 $sth->bindParam(':name', $name, PDO::PARAM_STR);
	 $pasword=md5($pasword);
	 $sth->bindParam(':pasword', $pasword, PDO::PARAM_STR);
	 $ret=$sth->execute();
	 $arr=$sth->fetchAll(PDO::FETCH_NUM);
	  var_dump($arr);
	  if($arr[0][0]==1){
		$_SESSION["name"]=$name;
		echo "登陆成功";
		header("Location:ingfo.php");
	   }else{
		echo "用户名或密码不正确";
	     }
   }else{
		echo "验证码错误";
	}
   
}

?>